package com.edu.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @Author:mx
 * @Date:2025/10/31-8:55:31
 */
public class Student implements BeanNameAware, ApplicationContextAware, InitializingBean, DisposableBean,Study {

    private int stuId;

    private String stuName;

    private int stuAge;

    private boolean graduated;//是否毕业

    private String beanName;

    public String getBeanName() {
        return beanName;
    }

    public int getStuId() {
        return stuId;
    }

    public void setStuId(int stuId) {
        System.out.println("2 正在 执行 属性的 setter方法 进行注入");
        this.stuId = stuId;
    }

    public String getStuName() {
        return stuName;
    }

    public void setStuName(String stuName) {
        this.stuName = stuName;
    }

    public int getStuAge() {
        return stuAge;
    }

    public void setStuAge(int stuAge) {
        this.stuAge = stuAge;
    }

    public boolean isGraduated() {
        return graduated;
    }

    public void setGraduated(boolean graduated) {
        this.graduated = graduated;
    }

    public Student() {
        System.out.println("1 执行了 Student 的 构造方法");
    }


    @Override
    public void setBeanName(String s) {
        System.out.println("3 执行了 各种 Aware接口");
        this.beanName = s;
    }

    public void myInit(){
        System.out.println("6 执行了 自定义的初始化方法");
        this.graduated = false;//设置学生未毕业，把学生信息记录到数据库
    }

    public void myDestroy(){
        this.graduated = true;
        System.out.println("10 执行了 自定义的销毁方法");
    }
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

    }

    @Override
    public String toString() {
        return "Student{" +
                "stuId=" + stuId +
                ", stuName='" + stuName + '\'' +
                ", stuAge='" + stuAge + '\'' +
                ", graduated=" + graduated +
                ", beanName='" + beanName + '\'' +
                '}';
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("5 执行了 InitializingBean的初始化方法");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("9 执行了 DisposableBean接口的销毁方法");
    }

    //学生的业务方法
    public void study(){
        System.out.println("8 执行自身的业务方法 正在学习");
    }
}
